	clear all

*cd
********************************************************************************************************************
***Predicted consumption 
*********************************************************************************************************************

*This file generates water consumption for the period 2016-2025 to conduct the welfare analysis.

*Base only on controls because I can predict water consumption using previous years info. I cannot do it with treated.
*All the pre-treatment data available, since 201301.


set more off
use data_long.dta, clear
	


keep if sorteo==0 

xtset cid fecha, monthly

tsappend, add(111)

drop ano mes
gen ano = yofd(dofm(fecha))
gen mes = month(dofm(fecha))
	
by cid, sort: egen mem1=mean(members)
by cid, sort: egen kit1=mean(kitchen)
by cid, sort: egen bat1=mean(bath)
by cid, sort: egen sho1=mean(shower)
by cid, sort: egen codcom1=mean(codcom)
by cid, sort: egen pfield1=mean(periodfield1)

drop codcom
rename codcom1 codcom

drop month
gen month=ano*100 + mes



keep m3 cid month codcom 
reshape wide m3, i(cid) j(month)

foreach m in 10 11 12{ 
egen av_`m'=rowmean(m32013`m' m32014`m' m32015`m')
forvalues x = 2016(1)2025{
replace m3`x'`m'=av_`m'
}
}


foreach m in 01 02 03 04 05 06 07 08 09{ 
egen av_`m'=rowmean(m32013`m' m32014`m' m32015`m' m32016`m')
forvalues x = 2017(1)2025{
replace m3`x'`m'=av_`m'
}
}

save predictedm3_osf.dta, replace


	
